/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroFuncionario.java
 *
 * Created on 16/08/2010, 07:43:14
 */
package view;

import DAO.FuncionarioDAO;
import controller.Funcionario;
import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Alcivando
 */
public class CadastroFuncionario extends javax.swing.JInternalFrame {

    /** Creates new form CadastroFuncionario */
    FuncionarioDAO dao;
    Funcionario funcionario;
    DefaultTableModel modelo;
    private static final CadastroFuncionario cadFunc;

    public CadastroFuncionario() {
        initComponents();
    }

    static {
        cadFunc = new CadastroFuncionario();
    }

    public static CadastroFuncionario getInstancia() {
        return cadFunc;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        txtComplemento = new javax.swing.JTextField();
        txtCidade = new javax.swing.JTextField();
        txtBairro = new javax.swing.JTextField();
        txtRua = new javax.swing.JTextField();
        uf = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtCep = new javax.swing.JFormattedTextField();
        txtNumero = new javax.swing.JFormattedTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtNome = new javax.swing.JTextField();
        txtCpf = new javax.swing.JFormattedTextField();
        txtTelefone = new javax.swing.JFormattedTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel8 = new javax.swing.JPanel();
        filtro = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabCod = new javax.swing.JTable();
        txtPesquisa = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtObs = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        btnNovoCliente = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        btnExluirCliente = new javax.swing.JButton();
        btnSalvarCliente = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Cadastro de Funcionários");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Endereço", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel19.setText("Complemento");

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel18.setText("N°");

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel17.setText("Rua");

        txtCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCidadeActionPerformed(evt);
            }
        });

        uf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));
        uf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ufActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Cidade");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("CEP");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel4.setText("Bairro");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel11.setText("UF");

        try {
            txtCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(txtRua, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(txtCep, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(uf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(138, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addGap(6, 6, 6)
                        .addComponent(txtRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19))
                        .addGap(6, 6, 6)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(jLabel4))
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(uf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(26, 26, 26)))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
        jPanel1.setFont(new java.awt.Font("Tahoma", 0, 12));

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setText("CPF");

        try {
            txtCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            txtTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel6.setText("Telefone");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Nome");

        txtCodigo.setEditable(false);

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel9.setText("Código");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel2)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        filtro.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nome", "Código", "CPF" }));

        jLabel1.setText("Pesquisar pelo");

        tabCod.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabCod.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabCodMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tabCod);

        txtPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPesquisaActionPerformed(evt);
            }
        });
        txtPesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPesquisaKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(filtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtPesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                .addGap(123, 123, 123))
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(filtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Pesquisar Funcionarios", jPanel8);

        txtObs.setColumns(20);
        txtObs.setRows(5);
        jScrollPane3.setViewportView(txtObs);

        jLabel8.setText("Observações do funcionário");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 479, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(73, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(92, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Observações", jPanel2);

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnNovoCliente.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btnNovoCliente.setText("Novo ");
        btnNovoCliente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNovoCliente.setVerifyInputWhenFocusTarget(false);
        btnNovoCliente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNovoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoClienteActionPerformed(evt);
            }
        });

        btnAlterar.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnAlterar.setText("Gravar");
        btnAlterar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAlterar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        btnExluirCliente.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnExluirCliente.setText("Excluir");
        btnExluirCliente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnExluirCliente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnExluirCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExluirClienteActionPerformed(evt);
            }
        });

        btnSalvarCliente.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnSalvarCliente.setText("Salvar");
        btnSalvarCliente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSalvarCliente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSalvarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarClienteActionPerformed(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnCancelar.setText("Cancelar");
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnNovoCliente, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnSalvarCliente, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                    .addComponent(btnAlterar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                    .addComponent(btnExluirCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnAlterar, btnCancelar, btnExluirCliente, btnNovoCliente, btnSalvarCliente});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnNovoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSalvarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExluirCliente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnAlterar, btnCancelar, btnExluirCliente, btnNovoCliente, btnSalvarCliente});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, 0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTabbedPane1, 0, 0, Short.MAX_VALUE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ufActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ufActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ufActionPerformed

    private void txtPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPesquisaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtPesquisaActionPerformed

    private void txtPesquisaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisaKeyReleased

        
        txtBairro.setEnabled(false);
        txtCep.setEnabled(false);
        txtCidade.setEnabled(false);
        txtComplemento.setEnabled(false);
        txtCpf.setEnabled(false);
        txtNome.setEnabled(false);
        txtNumero.setEnabled(false);
        txtObs.setEnabled(false);
        txtRua.setEnabled(false);
        txtTelefone.setEnabled(false);
        uf.setEnabled(false);

        modelo.setNumRows(0);

        ArrayList<Funcionario> listaFunc;

        try {
            dao = new FuncionarioDAO();
            if (!txtPesquisa.getText().isEmpty()) {
                if (filtro.getSelectedItem().toString().equals("Nome")) {
                    listaFunc = dao.retornaFuncionarioPorNome(txtPesquisa.getText().toUpperCase());
                } else if (filtro.getSelectedItem().toString().equals("Código")) {
                    listaFunc = dao.retornaFuncionarioPorCod(Integer.parseInt(txtPesquisa.getText().toUpperCase()));
                } else {
                    listaFunc = dao.retornaFuncionarioPorCpf(txtPesquisa.getText().toUpperCase());
                }
                for (Funcionario f : listaFunc) {
                    modelo.addRow(new String[]{Integer.toString(f.getCodFuncionario()), f.getNome(), f.getCpf(), f.getRua(), Integer.toString(f.getNumero()), f.getCidade()});
                }
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
}//GEN-LAST:event_txtPesquisaKeyReleased

    private void tabCodMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabCodMouseClicked

        funcionario = new Funcionario();
        int linha = tabCod.getSelectedRow();
        try {
            dao = new FuncionarioDAO();
            funcionario = dao.retornaFuncionarioPorCodigo(Integer.parseInt(tabCod.getValueAt(linha, 0).toString()));

            txtCodigo.setText(Integer.toString(funcionario.getCodFuncionario()));
            txtNome.setText(funcionario.getNome());
            txtBairro.setText(funcionario.getBairro());
            txtCidade.setText(funcionario.getCidade());
            txtComplemento.setText(funcionario.getComplemento());
            txtCpf.setText(funcionario.getCpf());
            txtNumero.setText(Integer.toString(funcionario.getNumero()));
            txtRua.setText(funcionario.getRua());
            txtTelefone.setText(funcionario.getTelefone());
            txtCep.setText(funcionario.getCep());
            txtObs.setText(funcionario.getObs());
            txtComplemento.setText(funcionario.getComplemento());

            btnSalvarCliente.setEnabled(false);
            btnNovoCliente.setEnabled(false);
            btnAlterar.setEnabled(true);
            btnExluirCliente.setEnabled(true);
            btnCancelar.setEnabled(true);

            txtBairro.setEnabled(true);
            txtCep.setEnabled(true);
            txtCidade.setEnabled(true);
            txtComplemento.setEnabled(true);
            txtCpf.setEnabled(true);
            txtNome.setEnabled(true);
            txtNumero.setEnabled(true);
            txtObs.setEnabled(true);
            txtRua.setEnabled(true);
            txtTelefone.setEnabled(true);
            uf.setEnabled(true);

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
}//GEN-LAST:event_tabCodMouseClicked

    private void btnNovoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoClienteActionPerformed
        txtNome.setText("");
        txtBairro.setText("");
        txtCidade.setText("");
        txtComplemento.setText("");
        txtCpf.setText("");
        txtNumero.setText("");
        txtRua.setText("");
        txtTelefone.setText("");
        txtCep.setText("");
        txtObs.setText("");
        txtComplemento.setText("");

        txtBairro.setEnabled(true);
        txtCep.setEnabled(true);
        txtCidade.setEnabled(true);
        txtComplemento.setEnabled(true);
        txtCpf.setEnabled(true);
        txtNome.setEnabled(true);
        txtNumero.setEnabled(true);
        txtObs.setEnabled(true);
        txtRua.setEnabled(true);
        txtTelefone.setEnabled(true);
        uf.setEnabled(true);
        try {
            dao = new FuncionarioDAO();
            txtCodigo.setText(Integer.toString(dao.retornaProximoID()));
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
        
         filtro.setEnabled(false);
        btnSalvarCliente.setEnabled(true);
        btnExluirCliente.setEnabled(false);
        btnAlterar.setEnabled(false);
        btnNovoCliente.setEnabled(false);
        btnCancelar.setEnabled(true);

        tabCod.setEnabled(false);
        txtPesquisa.setEnabled(false);
        uf.setEnabled(true);
}//GEN-LAST:event_btnNovoClienteActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed

        if (!txtNome.getText().equals("")) {
            funcionario = new Funcionario();
            funcionario.setCodFuncionario(Integer.parseInt(txtCodigo.getText().toUpperCase()));
        funcionario.setNome(txtNome.getText().toUpperCase());
        funcionario.setCpf(txtCpf.getText().toUpperCase());
        funcionario.setRua(txtRua.getText().toUpperCase());
        funcionario.setNumero(Integer.parseInt(txtNumero.getText().toUpperCase()));
        funcionario.setBairro(txtBairro.getText().toUpperCase());
        funcionario.setCidade(txtCidade.getText().toUpperCase());
        funcionario.setTelefone(txtTelefone.getText().toUpperCase());
        funcionario.setObs(txtObs.getText().toUpperCase());
        funcionario.setUf(uf.getSelectedItem().toString().toUpperCase());
        funcionario.setComplemento(txtComplemento.getText().toUpperCase());
        funcionario.setCep(txtCep.getText().toUpperCase());

            try {
                dao = new FuncionarioDAO();
                dao.atualizar(funcionario);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Os campos não foram preemchidos corretamente", "Erro", 0);
        }
        txtPesquisaKeyReleased(null);
}//GEN-LAST:event_btnAlterarActionPerformed

    private void btnExluirClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExluirClienteActionPerformed
        funcionario = new Funcionario();
        funcionario.setCodFuncionario(Integer.parseInt(txtCodigo.getText().toUpperCase()));
        funcionario.setNome(txtNome.getText().toUpperCase());
        funcionario.setCpf(txtCpf.getText().toUpperCase());
        funcionario.setRua(txtRua.getText().toUpperCase());
        funcionario.setNumero(Integer.parseInt(txtNumero.getText().toUpperCase()));
        funcionario.setBairro(txtBairro.getText().toUpperCase());
        funcionario.setCidade(txtCidade.getText().toUpperCase());
        funcionario.setTelefone(txtTelefone.getText().toUpperCase());
        funcionario.setObs(txtObs.getText().toUpperCase());
        funcionario.setUf(uf.getSelectedItem().toString().toUpperCase());
        funcionario.setComplemento(txtComplemento.getText().toUpperCase());
        funcionario.setCep(txtCep.getText().toUpperCase());

        txtNome.setText("");
        txtBairro.setText("");
        txtCidade.setText("");
        txtComplemento.setText("");
        txtCpf.setText("");
        txtNumero.setText("");
        txtRua.setText("");
        txtTelefone.setText("");
        txtCep.setText("");
        txtObs.setText("");
        txtComplemento.setText("");
        txtCodigo.setText("");

        

        try {
            dao = new FuncionarioDAO();
            dao.remover(funcionario);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
        txtPesquisaKeyReleased(null);

        btnAlterar.setEnabled(false);
        btnExluirCliente.setEnabled(false);

}//GEN-LAST:event_btnExluirClienteActionPerformed

    private void btnSalvarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarClienteActionPerformed

        try {
        if(txtNome.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Erro: Você não preencheu corretamente algum dos campos." , "Erro", 0);

            }else{
        funcionario = new Funcionario();
        funcionario.setCodFuncionario(Integer.parseInt(txtCodigo.getText().toUpperCase()));
        funcionario.setNome(txtNome.getText().toUpperCase());
        funcionario.setCpf(txtCpf.getText().toUpperCase());
        funcionario.setRua(txtRua.getText().toUpperCase());
        funcionario.setNumero(Integer.parseInt(txtNumero.getText().toUpperCase()));
        funcionario.setBairro(txtBairro.getText().toUpperCase());
        funcionario.setCidade(txtCidade.getText().toUpperCase());
        funcionario.setTelefone(txtTelefone.getText().toUpperCase());
        funcionario.setObs(txtObs.getText().toUpperCase());
        funcionario.setUf(uf.getSelectedItem().toString().toUpperCase());
        funcionario.setComplemento(txtComplemento.getText().toUpperCase());
        funcionario.setCep(txtCep.getText().toUpperCase());

        txtNome.setText("");
        txtBairro.setText("");
        txtCidade.setText("");
        txtComplemento.setText("");
        txtCpf.setText("");
        txtNumero.setText("");
        txtRua.setText("");
        txtTelefone.setText("");
        txtCep.setText("");
        txtObs.setText("");
        txtComplemento.setText("");
        txtCodigo.setText("");

 filtro.setEnabled(true);
        
            dao = new FuncionarioDAO();
            dao.adiciona(funcionario);
        

        txtPesquisaKeyReleased(null);
        
        btnExluirCliente.setEnabled(false);
        btnAlterar.setEnabled(false);
        btnNovoCliente.setEnabled(true);
        tabCod.setEnabled(true);
        txtPesquisa.setEnabled(true);
        btnSalvarCliente.setEnabled(false);
        }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
}//GEN-LAST:event_btnSalvarClienteActionPerformed
    private void formWindowOpened(java.awt.event.WindowEvent evt) {

        //TABELA
        String[] colunas = new String[]{"", "", "", "", "", ""};
        String[][] dados = new String[][]{};

        modelo = new DefaultTableModel(dados, colunas);

        tabCod.setModel(modelo);
        tabCod.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Código");
        tabCod.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Nome");
        tabCod.getTableHeader().getColumnModel().getColumn(2).setHeaderValue("CPF");
        tabCod.getTableHeader().getColumnModel().getColumn(3).setHeaderValue("Rua");
        tabCod.getTableHeader().getColumnModel().getColumn(4).setHeaderValue("Número");
        tabCod.getTableHeader().getColumnModel().getColumn(5).setHeaderValue("Cidade");

        tabCod.setPreferredScrollableViewportSize(new Dimension(2300, 0));

    }

   
    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        txtCodigo.setText("");
        txtNome.setText("");
        txtBairro.setText("");
        txtCidade.setText("");
        txtComplemento.setText("");
        txtCpf.setText("");
        txtNumero.setText("");
        txtRua.setText("");
        txtTelefone.setText("");
        txtCep.setText("");
        txtObs.setText("");
        txtComplemento.setText("");
        txtCodigo.setText("");
        txtPesquisa.setText("");

        btnExluirCliente.setEnabled(false);
        btnAlterar.setEnabled(false);
        btnNovoCliente.setEnabled(true);
        btnSalvarCliente.setEnabled(false);

        tabCod.setEnabled(true);
        txtPesquisa.setEnabled(true);
        txtBairro.setEnabled(false);
        txtCep.setEnabled(false);
        txtCidade.setEnabled(false);
        txtComplemento.setEnabled(false);
        txtCpf.setEnabled(false);
        txtNome.setEnabled(false);
        txtNumero.setEnabled(false);
        txtObs.setEnabled(false);
        txtRua.setEnabled(false);
        txtTelefone.setEnabled(false);
        
        filtro.setEnabled(true);
        uf.setEnabled(false);
        txtPesquisaKeyReleased(null);
    }//GEN-LAST:event_btnCancelarActionPerformed
 public void primeiraLeitura() {

        btnSalvarCliente.setEnabled(false);
        btnAlterar.setEnabled(false);
        btnExluirCliente.setEnabled(false);
        btnCancelar.setEnabled(false);
        btnNovoCliente.setEnabled(true);

        txtNome.setText("");
        txtBairro.setText("");
        txtCidade.setText("");
        txtComplemento.setText("");
        txtCpf.setText("");
        txtNumero.setText("");
        txtRua.setText("");
        txtTelefone.setText("");
        txtCep.setText("");
        txtObs.setText("");
        txtComplemento.setText("");
        txtCodigo.setText("");

        txtBairro.setEnabled(false);
        txtCep.setEnabled(false);
        txtCidade.setEnabled(false);
        txtComplemento.setEnabled(false);
        txtCpf.setEnabled(false);
        txtNome.setEnabled(false);
        txtNumero.setEnabled(false);
        txtObs.setEnabled(false);
        txtRua.setEnabled(false);
        txtTelefone.setEnabled(false);
        uf.setEnabled(false);
filtro.setEnabled(true);
        formWindowOpened(null);
        txtPesquisaKeyReleased(null);

        setVisible(true);

    }
    private void txtCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCidadeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCidadeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnExluirCliente;
    private javax.swing.JButton btnNovoCliente;
    private javax.swing.JButton btnSalvarCliente;
    private javax.swing.JComboBox filtro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable tabCod;
    private javax.swing.JTextField txtBairro;
    private javax.swing.JFormattedTextField txtCep;
    private javax.swing.JTextField txtCidade;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtComplemento;
    private javax.swing.JFormattedTextField txtCpf;
    private javax.swing.JTextField txtNome;
    private javax.swing.JFormattedTextField txtNumero;
    private javax.swing.JTextArea txtObs;
    private javax.swing.JTextField txtPesquisa;
    private javax.swing.JTextField txtRua;
    private javax.swing.JFormattedTextField txtTelefone;
    private javax.swing.JComboBox uf;
    // End of variables declaration//GEN-END:variables
}
